import storage from '@/storage'

export default {
  state: () => ({
    api_token: storage.get(storage.api_token),
    user: null
  }),
  mutations: {
    setApiToken(state, api_token) {
      state.api_token = api_token
    },
    setUser(state, user) {
      state.user = { ...user }
    }
  },
  actions: {
    setApiToken ({state, commit}, payload) {
      commit(payload.api_token)
      storage.set(storage.api_token, api_token)
    },
    setUser({state, commit}, payload) {
      commit(payload.user)
    }
  }
}